import os
import imagesize
from tqdm import tqdm
from utils import ReadXml, WriteXml


AnnotationsPath = r"/media/fang/TOSHIBA EXT/Temp/600X300/B"
JEPGPath = r'/media/fang/TOSHIBA EXT/Temp/600X300/B'

DeleteLabelNames = ['10', '11', '12', '13', '15']

for root, dirs, files in os.walk(AnnotationsPath):
    for file in tqdm(files):
        if file[-1] == 'l':
            Infos = ReadXml(root + "/" + file)
            NewInfos = [root + "/" + file]
            for Info in Infos:
                if Info[-1] not in DeleteLabelNames:
                    NewInfos.append(Info)
            if not Infos == NewInfos[1:]:
                W, H = imagesize.get(JEPGPath + "/" + file[:-3] + "jpg")
                WriteXml(NewInfos, W, H)


